<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8" />
		<title>v-on:keydown</title>
		<script src="js/vuejs-2.5.16.js"></script>
	</head>

	<body>
		<div id="app">
			vue事件<input type="text" v-on:keydown="fun($event)">
			传统事件<input type="text" onkeydown="fun1()">
			事件<input type="text" @keydown.enter="fun2()">
			事件2<input type="text" @keydown.space="fun3()">
		</div>
	</body>
	<script>
		//view model
		new Vue({
			el:"#app",
			methods:{
			    fun:function (event) {
			        var keyCode = event.keyCode;
			        if (keyCode<48||keyCode>57) {
			            //阻止事件默认行为
			            event.preventDefault();
					}
                },
                fun2:function () {
					alert("你按下的是回车键")
                },
				fun3:function () {
					alert("你按下的是空格")
                }
			}
		})
		function fun1() {
			var keyCode = event.keyCode;
			if (keyCode>=48&&keyCode<=57){
			    event.preventDefault();
			}
        }
	</script>
</html>